package sparrowGui.components.item
{
	import flash.events.MouseEvent;
	
	import sparrowGui.event.ItemEvent;
	import sparrowGui.i.ITreeNode;
	
	/**
	 * 列表项，有六状态，有经过移动事件，不过没有选中事件
	 * @author Pelephone
	 * @website http://cnblogs.com/pelephone
	 */
	public class STreeChildItem extends SListItem
	{
		/**
		 * 选中状态
		 */
		private var _selected:Boolean = false;
		
		/**
		 * 构造树形组件子项
		 * @param uiVars
		 * @return 
		 */
		public function STreeChildItem(uiVars:Object=null)
		{
			super(uiVars);
		}
		
		override public function update(o:Object):void
		{
			if(o is ITreeNode)
				super.update(o.txtName);
			else
				super.update(o);
		}
		
		override protected function addSkinListen():void
		{
			super.addSkinListen();
			skin.addEventListener(MouseEvent.CLICK,onSelectEvt);
		}
		
		override protected function removeSkinListen():void
		{
			super.removeSkinListen();
			skin.removeEventListener(MouseEvent.CLICK,onSelectEvt);
		}
		
		protected function onSelectEvt(e:MouseEvent):void
		{
			dispatchEvent(new ItemEvent(ItemEvent.ITEM_SELECT_CHANGE));
		}
		
		///////////////////////////////////
		// get/set
		//////////////////////////////////
		
		
		override public function getDefaultUIName():String
		{
			return "richItem";
		}
		
		/**
		 * 选中状态
		 */
		override public function set selected(value:Boolean):void
		{
			// 状态跟原状态不同时才重设
			if(_selected != value)
			{
				if(value){
					super.removeSkinListen();
					changeState(SELECTSTATE_NAME);
				}else{
					super.addSkinListen();
					changeState(UPSTATE_NAME);
				}
				_selected = value;
			}
		}
		
		override public function get selected():Boolean
		{
			return _selected;
		}
	}
}